/**
 * @file Define the wall web controller
 * 
 * @author Steve Gao<gaofu@parllay.com>
 */
const WebBaseController = require('./web-base-controller');
const {SystemServices}  = require('../../constants');

class WallController extends WebBaseController {

    get wallService() {
        if (!this._wallService) {
            this._wallService = this.getSystemService(SystemServices.WALL_SERVICE);
        }

        return this._wallService;
    }

    get userService() {
        if (!this._userService) {
            this._userService = this.getSystemService(SystemServices.USER_SERVICE);
        }

        return this._userService;
    }

    get wechatService() {
        if (!this._wechatService) {
            this._wechatService = this.getSystemService(SystemServices.WECHAT_SERVICE);
        }
        return this._wechatService;
    }

    get dianpingService() {
        if (!this._dianpingService) {
            this._dianpingService = this.getSystemService(SystemServices.DIANPING_SERVICE);
        }

        return this._dianpingService;
    }

    get name() {
        return 'WallController';
    }

    get handlersPath() {
        return 'wall';
    }

    /**
     * Wrap the WallService's addWallAuthor method
     * 
     * @name addWallAuthor
     * @param {String} wallId - The wall id
     * @param {String} wallUserId - The wall user id
     * @param {String} systemUserId - The super admin user id of wall
     * @param {Function} parentCallback - The callback function
     * 
     * @returns {void}
     */
    addWallAuthor(wallId, wallUserId, systemUserId, parentCallback) {
        this.wallService.addWallAuthor(wallId, wallUserId, systemUserId, (result) => {
            parentCallback(result);
        });
    }

    /**
     * Wrap the WallService's removeWallAuthor method
     * 
     * @param {String} wallId - The wall id
     * @param {String} wallUserId - The wall user id
     * @param {String} systemUserId - The super admin user id of wall
     * @param {Function} parentCallback - The callback function
     * 
     * @returns {void}
     */
    removeWallAuthor(wallId, wallUserId, systemUserId, parentCallback) {
        this.wallService.removeWallAuthor(wallId, wallUserId, systemUserId, (result) => {
            parentCallback(result);
        });
    }

    /**
     * Wrap the WallService's addWallAdministrator method
     * 
     * @name addWallAdministrator
     * @param {String} wallId - The wall id
     * @param {String} wallUserId - The wall user id
     * @param {String} systemUserId - The super admin user id of wall
     * @param {Function} parentCallback - The callback function
     * 
     * @returns {void}
     */
    addWallAdministrator(wallId, wallUserId, systemUserId, parentCallback) {
        this.wallService.addWallAdministrator(wallId, wallUserId, systemUserId, (result) => {
            parentCallback(result);
        });
    }

    /**
     * Wrap the WallService's removeWallAdministrator method
     * 
     * @param {String} wallId - The wall id
     * @param {String} wallUserId - The wall user id
     * @param {String} systemUserId - The super admin user id of wall
     * @param {Function} parentCallback - The callback function
     * 
     * @returns {void}
     */
    removeWallAdministrator(wallId, wallUserId, systemUserId, parentCallback) {
        this.wallService.removeWallAdministrator(wallId, wallUserId, systemUserId, (result) => {
            parentCallback(result);
        });
    }

    /**
     * Wrap the WallService's getWallUserProfileWithAssets method
     * 
     * @name getWallUserProfileWithAssets
     * @param {String} wallUserId - The wall user id
     * @param {Function} parentCallback - The callback function
     * 
     * @returns {void}
     */
    getWallUserProfileWithAssets(wallUserId, parentCallback) {
        this.wallService.getWallUserProfileWithAssets(wallUserId, (result) => {
            parentCallback(result);
        });
    }

    /**
     * Wrap the WallService's getWallUserProfile method
     * 
     * @name getWallUserProfile
     * @param {String} wallUserId - The wall user id
     * @param {Function} parentCallback - The callback function
     * 
     * @returns {void}
     */
    
    getWallUserProfile(wallUserId, parentCallback) {
        this.wallService.getWallUserProfile(wallUserId, (result) => {
            parentCallback(result);
        });
    }

    /**
     * Wrap the WallService's updateWallUserProfile method
     * 
     * @name updateWallUserProfile
     * @param {String} wallUserId - The wall user id
     * @param {Object} data - The user profile data
     * 
     * @returns {void}
     */
    updateWallUserProfile(wallUserId, data, parentCallback) {
        this.wallService.updateWallUserProfile(wallUserId, data, (result) => {
            parentCallback(result);
        });
    }

    /**
     * Wrap the UserService's getPlanInfo method
     * 
     * @name getPlanInfo
     * @param {String} userId - The user id
     * @param {Function} parentCallback - The callback function
     * 
     * @returns {void}
     */
    getPlanInfo(userId, parentCallback) {
        this.userService.getPlanInfo(userId, (result) => {
            parentCallback(result);
        });
    }

    /**
     * Wrap the WallService's getWallById method
     * 
     * @name getWallById
     * @param {String} wallId - The wall id
     * @param {Function} parentCallback - The callback function
     * 
     * @returns {void}
     */
    getWallById(wallId, parentCallback) {
        this.wallService.getWallById(wallId, (data) => {
            parentCallback(data);
        });
    }

    /**
     * Wrap the WallService's saveOrUpdateWall method
     * 
     * @name saveOrUpdateWall
     * @param {Object} data - The wall data
     * @param {Function} parentCallback - The callback function
     * 
     * @memberOf WallController
     */
    saveOrUpdateWall(data, parentCallback) {
        this.wallService.saveOrUpdateWall(data, (data) => {
            parentCallback(data);
        });
    }

    /**
     * Wrap the WallService's getWallsByUserIdentifier
     * 
     * @name getWallsByUserIdentifier
     * @param {String} identifier - The user identifier
     * @param {Function} parentCallback - The callback function
     * 
     * @returns {void}
     */
    getWallsByUserIdentifier(identifier, parentCallback) {
        this.wallService.getWallsByUserIdentifier(identifier, (walls) => {
            parentCallback(walls);
        });
    }
    
    /**
     * Wrap the WallService's getWallsByUserId method
     * 
     * @name getWallsByUserId
     * @param {String} userId - The user id
     * @param {String} appId - The app id
     * @param {Function} parentCallback - The callback function
     * 
     * @returns {void}
     */
    getWallsByUserId(userId, parentCallback) {
        this.wallService.getWallsByUserId(userId, (walls) => {
            parentCallback(walls);
        });
    }

    /**
     * Wrap the WallService's doPhotoAction method
     * 
     * @name doPhotoAction
     * @param {String} action - The photo action
     * @param {String} wallId - The wall id
     * @param {String} photoId - The photo id
     * @param {String} userId - The user's id which do action
     * @param {Object} data - The additional data
     * @param {Function} parentCallback - The callback function
     * 
     * @returns {void}
     */
    doPhotoAction(action, wallId, photoId, userId, data, parentCallback) {
        this.wallService.doPhotoAction(action, wallId, photoId, userId, data, (result) => {
            parentCallback(result);
        });
    }

    /**
     * Wrap the WallService's saveAssetComment method
     * 
     * @name saveAssetComment
     * @param {Object} data - The comment data
     * @param {Function} parentCallback - The callback function
     * 
     * @returns {void}
     */
    saveAssetComment(data, parentCallback) {
        this.wallService.saveAssetComment(data, (result) => {
            parentCallback(result);
        });
    }

    /**
     * Wrap the WallService's getCommentsByAssetId method
     * 
     * @name getCommentsByAssetId
     * @param {String} assetId - The asset id
     * @param {Object} params - The parameters
     * @param {Function} parentCallback - The callback function
     * 
     * @returns {void}
     */
    getCommentsByAssetId(assetId, params, parentCallback) {
        this.wallService.getCommentsByAssetId(assetId, params, (result) => {
            parentCallback(result);
        });
    }

    /**
     * Wrap the WallService's removeCommentById method
     * 
     * @name removeCommentById
     * @param {String} commentId - The comment id
     * @param {Function} parentCallback - The callback function
     * 
     * @returns {void}
     */
    removeCommentById(commentId, parentCallback) {
        this.wallService.removeCommentById(commentId, (result) => {
            parentCallback(result);
        });
    }

    /**
     * Wrap the WallService's getPhotosByWallId method
     * 
     * @name getPhotosByWallId
     * @param {String} wallId - The wall id
     * @param {Object} params - The parameters
     * @param {Function} parentCallback - The callback function
     * 
     * @returns {void}
     */
    getPhotosByWallId(wallId, params, parentCallback) {
        this.wallService.getPhotosByWallId(wallId, params , (data) => {
            parentCallback(data);
        });
    }

    /**
     * Wrap the WallService's getLinkStatisticsByWallId method
     * 
     * @name getLinkStatisticsByWallId
     * @param {String} wallId - The wall id
     * @param {Object} params - The parameters
     * @param {Function} parentCallback - The callback function
     * 
     * @returns {void}
     */
    getLinkStatisticsByWallId(wallId, params, parentCallback) {
        this.wallService.getLinkStatisticsByWallId(wallId, params, (data) => {
            parentCallback(data);
        });
    }

    /**
     * Save wechat photo
     */
    //TODO: Need to refactor, merge the 2 save photo functions into one
    saveOrUpdateWallPhoto(wallId, message, serverId, ratio, link, userInfo, parentCallback) {
        this.wallService.saveOrUpdateWallPhoto(wallId, message, serverId, ratio, link, userInfo, (result) => {
            parentCallback(result);
        });
    }
    /**
     * Save administrator's photo
     */
    //TODO: Need to refactor
    savePhotoAssset(wallId, data, userInfo, parentCallback) {
        this.wallService.savePhotoAssset(wallId, data, userInfo, (result) => {
            parentCallback(result);
        });
    }

    getAssetById(assetId, parentCallback) {
        this.wallService.getAssetById(assetId, (result) => {
            parentCallback(result);
        });
    }

    updateAssetById(wallId, assetId, data, userId, parentCallback) {
        this.wallService.updateAssetById(wallId, assetId, data, userId, (result) => {
            parentCallback(result);
        });
    }

    /**
     * Wrap the WallService's getWallUsersByWallId method
     * 
     * @name getWallUsersByWallId
     * @param {String} wallId - The wall id
     * @param {Object} params - The query parameters
     * @param {Function} parentCallback - The callback function
     */
    getWallUsersByWallId(wallId, params, parentCallback) {
        this.wallService.getWallUsersByWallId(wallId, params, (result) => {
            parentCallback(result);
        });
    }

    /**
     * Get WeChat Jssdk config, wrap the WeChatService's getWeChatJssdkConfig method
     */
    //TODO: Need refactor this function
    getWeChatJssdkConfig(appId, request, parentCallback) {
        this.wechatService.getWeChatJssdkConfig(appId, request, (config) => {
            parentCallback(config);
        });
    }

    /**
     * Get WeChat user's oauth url, wrap the WeChatService's getWeChatUserOAuthUrl method
     */
    //TODO: Need refactor this function
    getWeChatUserOAuthUrl(appId, request, parentCallback) {
        this.wechatService.getWeChatUserOAuthUrl(appId, request, (url) => {
            parentCallback(url);
        });
    }

    /**
     * Ensure the system generate an anonymous user, wrap the WallService's ensureAnonymousUser
     */
    //TODO: Need refactor
    ensureAnonymousUser(request, wallUserId, parentCallback) {
        this.wallService.ensureAnonymousUser(request, wallUserId, (userId) => {
            parentCallback(userId);
        });
    }

    /**
     * Wrap the WallService's saveOrUpdateWallSettings method
     * 
     * @name saveOrUpdateWallSettings
     * @param {String} wallId - The wall id
     * @param {Object} settings - The settings Object
     * 
     * @returns {void}
     */
    saveOrUpdateWallSettings(wallId, settings, parentCallback) {
        this.wallService.saveOrUpdateWallSettings(wallId, settings, (result) => {
            parentCallback(result);
        });
    }

    fetchDianpingReviewsData(wallId, userId, shopId, host, parentCallback) {
        this.dianpingService.fetchDianpingReviewsData(wallId, userId, shopId, host, (result) => {
            parentCallback(result);
        });
    }

    /**
     * 获取最新的上传的新数据
     */
    getLatestUploadPhotos(params, parentCallback) {
        this.wallService.getLatestUploadPhotos(params, (result) => {
            parentCallback(result);
        });
    }
}

exports.WallController = WallController;